﻿/**
 * 
 * Copyright 2009, 2010 Mike Jamer [email: mikejamer@gmail.com ]
 * 
 * This File is part of Moose IRC
 * 
 * MooseIRC is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * MooseIRC is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with MooseIRC.  If not, see <http://www.gnu.org/licenses/>.
 * 
 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using moose.irc.extension;

namespace moose.irc.actions.responses {

    [CLSCompliant(true)]
    [Action(
        Name = "moose-std-rsp-generic",
        Description = "Generic response, causes status message event, to echo the response into the server status terminal",
        Author = "Mike MacKenzie-Jamer<mikejamer@gmail.com>",
        Version = "0.1",
        Type = ActionTypes.Response)]
    [Trigger(TriggerText = "004")]
    [Trigger(TriggerText = "005")]
    [Trigger(TriggerText = "251")]
    [Trigger(TriggerText = "252")]
    [Trigger(TriggerText = "253")]
    [Trigger(TriggerText = "254")]
    [Trigger(TriggerText = "255")]
    [Trigger(TriggerText = "265")]
    [Trigger(TriggerText = "266")]
    [Trigger(TriggerText = "250")]
    [Trigger(TriggerText = "375")] //MOTD Start
    [Trigger(TriggerText = "372")] //MOTD --May break this out into something else, but for now, its fine...
    [Trigger(TriggerText = "376")] //END MOTD
    public sealed class GenericResponse : IrcAction {

        /// <summary>
        /// While this likely wont fire on anything but registered, lets leave that wide open, its just echoing...
        /// </summary>
        /// <returns></returns>
        public override IrcSessionStates valid_states() {
            return IrcSessionStates.Connected | IrcSessionStates.Disconnected | IrcSessionStates.None | IrcSessionStates.Registered;
        }

        public override void action(IrcSession session, IrcMessage message) {
            StringBuilder sbResponse = new StringBuilder();

            for (int i = 1; i < message.Arguments.Length; i++) {
                sbResponse.Append(message.Arguments[i]);
                sbResponse.Append(' ');
            }
            session.notify_event(IrcEvent.createEchoEvent(sbResponse.ToString()));

            return;
        }
    }
}
